﻿//$("#SearchProjectTextBox").autocomplete({
//    source: function (request, response) {
//        $.ajax({
//            url: "/Project/Search",
//            type: "POST",
//            dataType: "json",
//            data: {
//                Keyword: request.term,
//                ReturnType: "json"
//            },
//            success: function (projects) {
//                response($.map(projects, function (project) {
//                    return {
//                        label: project.Name,
//                        value: project.Id
//                    }
//                }));
//            }
//        });
//    },
//    minLength: 2,
//    select: function (event, project) {
//        $("#ProjectId").val(project.value);
//    },
//    open: function () {
//        $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
//    },
//    close: function () {
//        $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
//    }
//});
$("#SearchProjectTextBox").autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "http://localhost:2559/Project/Search",
            type: "POST",
            dataType: "json",
            data: {
                Keyword: request.term,
                ReturnType: "json"
            },
            success: function (projects) {
				alert("Sussess");
                response($.map(projects, function (project) {
                    return {
                        label: project.Name,
                        value: project.Name,
                        projectId: project.Id
                    }
                }));
            }
        });
    },
    minLength: 1,
    select: function (event, ui) {
    },
    open: function () {
		alert("Open");
        $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
    },
    close: function () {
        $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
    }
});

/*var availableTags = [
			"ActionScript",
			"AppleScript",
			"Asp",
			"BASIC",
			"C",
			"C++",
			"Clojure",
			"COBOL",
			"ColdFusion",
			"Erlang",
			"Fortran",
			"Groovy",
			"Haskell",
			"Java",
			"JavaScript",
			"Lisp",
			"Perl",
			"PHP",
			"Python",
			"Ruby",
			"Scala",
			"Scheme"
		];
$("#SearchProjectTextBox").autocomplete({
    source: availableTags
});*/

		function log( message ) {
			$( "<div/>" ).text( message ).prependTo( "#log" );
			$( "#log" ).attr( "scrollTop", 0 );
		}

		$( "#SearchProjectTextBox" ).autocomplete({
			source: function( request, response ) {
				$.ajax({
					url: "http://ws.geonames.org/searchJSON",
					dataType: "jsonp",
					data: {
						featureClass: "P",
						style: "full",
						maxRows: 12,
						name_startsWith: request.term
					},
					success: function( data ) {
						response( $.map( data.geonames, function( item ) {
							return {
								label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
								value: item.name
							}
						}));
					}
				});
			},
			minLength: 2,
			select: function( event, ui ) {
				log( ui.item ?
					"Selected: " + ui.item.label :
					"Nothing selected, input was " + this.value);
			},
			open: function() {
				$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
			},
			close: function() {
				$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
			}
		});